﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WineItem.cs" company="Simon Carpentier">
//   Microsoft Reciprocal License (Ms-RL)
// </copyright>
// <summary>
//   Defines the WineItem type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace VinoCellar.Model
{
    using System.ComponentModel;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;

    /// <summary>
    /// Représente une bouteille de vin dans le modèle du domaine
    /// </summary>
    [Table]
    public class WineItem : INotifyPropertyChanged, INotifyPropertyChanging
    {
        /// <summary>
        /// Version de l'enregistrement
        /// </summary>
        /// <remarks>Version column aids update performance.</remarks>
        [Column(IsVersion = true)]
        private Binary version;

        /// <summary>
        /// Event that fires when a property has changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Event that fires when a property is about to change
        /// </summary>
        public event PropertyChangingEventHandler PropertyChanging;

        /// <summary>
        /// Used to notify that a property changed
        /// </summary>
        /// <param name="propertyName">Name of the property that changed</param>
        private void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Used to notify that a property is about to change
        /// </summary>
        /// <param name="propertyName">Name of the property that is about to change</param>
        private void NotifyPropertyChanging(string propertyName)
        {
            if (this.PropertyChanging != null)
            {
                this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        private int wineItemId;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int WineItemId
        {
            get { return this.wineItemId; }
            set
            {
                if (this.wineItemId != value)
                {
                    this.NotifyPropertyChanging("WineItemId");
                    this.wineItemId = value;
                    this.NotifyPropertyChanged("WineItemId");
                }
            }
        }

        private string wineName;

        [Column]
        public string WineName
        {
            get { return this.wineName; }
            set
            {
                if (this.wineName != value)
                {
                    this.NotifyPropertyChanging("WineName");
                    this.wineName = value;
                    this.NotifyPropertyChanged("WineName");
                }
            }
        }

        private string wineCategory;

        [Column]
        public string WineCategory
        {
            get { return this.wineCategory; }
            set
            {
                if (this.wineCategory != value)
                {
                    this.NotifyPropertyChanging("WineCategory");
                    this.wineCategory = value;
                    this.NotifyPropertyChanged("WineCategory");
                }
            }
        }

        private string wineCountry;

        [Column]
        public string WineCountry
        {
            get { return this.wineCountry; }
            set
            {
                if (this.wineCountry != value)
                {
                    this.NotifyPropertyChanging("WineCountry");
                    this.wineCountry = value;
                    this.NotifyPropertyChanged("WineCountry");
                }
            }
        }

        private double _winePrice;

        [Column]
        public double WinePrice
        {
            get { return this._winePrice; }
            set
            {
                if (this._winePrice != value)
                {
                    this.NotifyPropertyChanging("WinePrice");
                    this._winePrice = value;
                    this.NotifyPropertyChanged("WinePrice");
                }
            }
        }

        private string _wineYear;

        [Column]
        public string WineYear
        {
            get { return this._wineYear; }
            set
            {
                if (this._wineYear != value)
                {
                    this.NotifyPropertyChanging("WineYear");
                    this._wineYear = value;
                    this.NotifyPropertyChanged("WineYear");
                }
            }
        }

        private string _wineUrl;

        [Column]
        public string WineUrl
        {
            get { return this._wineUrl; }
            set
            {
                if (this._wineUrl != value)
                {
                    this.NotifyPropertyChanging("WineUrl");
                    this._wineUrl = value;
                    this.NotifyPropertyChanged("WineUrl");
                }
            }
        }

        private string _wineRegion;

        [Column]
        public string WineRegion
        {
            get { return this._wineRegion; }
            set
            {
                if (this._wineRegion != value)
                {
                    this.NotifyPropertyChanging("WineRegion");
                    this._wineRegion = value;
                    this.NotifyPropertyChanged("WineRegion");
                }
            }
        }

        private string _wineSubregion;

        [Column]
        public string WineSubregion
        {
            get { return this._wineSubregion; }
            set
            {
                if (this._wineSubregion != value)
                {
                    this.NotifyPropertyChanging("WineSubregion");
                    this._wineSubregion = value;
                    this.NotifyPropertyChanged("WineSubregion");
                }
            }
        }

        private string _wineAppellation;

        [Column]
        public string WineAppellation
        {
            get { return this._wineAppellation; }
            set
            {
                if (this._wineAppellation != value)
                {
                    this.NotifyPropertyChanging("WineAppellation");
                    this._wineAppellation = value;
                    this.NotifyPropertyChanged("WineAppellation");
                }
            }
        }

        private string _winePictureUrl;

        [Column]
        public string WinePictureUrl
        {
            get { return this._winePictureUrl; }
            set
            {
                if (this._winePictureUrl != value)
                {
                    this.NotifyPropertyChanging("WinePictureUrl");
                    this._winePictureUrl = value;
                    this.NotifyPropertyChanged("WinePictureUrl");
                }
            }
        }

        private string _wineUpc;

        [Column]
        public string WineUpc
        {
            get { return this._wineUpc; }
            set
            {
                if (this._wineUpc != value)
                {
                    this.NotifyPropertyChanging("WineUpc");
                    this._wineUpc = value;
                    this.NotifyPropertyChanged("WineUpc");
                }
            }
        }
    }
}
